package com.qf.j2205.service.impl;

import com.qf.j2205.dao.BackUpMapper;
import com.qf.j2205.entity.BackUp;
import com.qf.j2205.entity.vo.BackUpVo;
import com.qf.j2205.service.BackUpService;
import com.qf.j2205.util.MybitesUtil;

import java.util.List;

/**
 * @ClassName BankUpServiceImpl
 * @Description TODO
 * @Author Windy
 * @Date 2022/8/18 15:11
 * @Version 1.0
 **/
public class BackUpServiceImpl implements BackUpService {
    @Override
    public boolean addBackup(BackUp back) {
        //通过工具类创建mapper实例
        BackUpMapper mapper = MybitesUtil.getSession().getMapper(BackUpMapper.class);
        int i = mapper.addBackup(back);
        if (i >= 0) {
            MybitesUtil.commitWork();
            MybitesUtil.closeAll();
            return true;
        }
        MybitesUtil.rollbackWork();
        MybitesUtil.closeAll();
        return false;
    }

    /**
     * 查询全部
     *
     * @return
     */
    @Override
    public List<BackUpVo> findAll(){
        BackUpMapper mapper = MybitesUtil.getSession().getMapper(BackUpMapper.class);
        List<BackUpVo> all = mapper.findAll();
        if (all != null) {
            return all;
        }
        return null;
    }
    /**
     * 根据id删除
     * @param id
     * @return
     */
    public boolean deleteBackup(int id){
        BackUpMapper mapper = MybitesUtil.getSession().getMapper(BackUpMapper.class);
        int i = mapper.deleteBackup(id);
        if (i >= 0) {
            MybitesUtil.commitWork();
            MybitesUtil.closeAll();
            return true;
        }
        MybitesUtil.rollbackWork();
        MybitesUtil.closeAll();
        return false;
    }
}
